Nowadays a large amount of applications need to access databases in order to obtain necessary data. For example, a database-related application written in the Java language typically uses JDBC (Java Database Connection) to interact with a database. Here, a connection represents a channel, and various applications can read/write data to the database via such channels.
To access data from application, a database connection needs to be set up for each application request. Due to frequent access to the database, the operation of setting up database connections consumes a large amount of memory. To reduce memory usage, a new mechanism named “pool” is introduced into management of the connections. That is, a certain number of connections are placed in a connection pool in advance, and when a connection needs to set up, one connection is taken out of the pool and then placed back after completion. However, the management of connections via connection pools in the prior art is restricted to the basic allocation of connections. Moreover, the usage of a connection by an application, whether the usage is reasonable or not, is not under control by application server. In fact, the improper usage of a connection by an application will cause resource conflicts, thread hangs and even system crashes. There is a variety of improper usages of connections. One example of an improper usage is a connection leak, i.e. some applications fail to close a connection after obtaining it and the connection is hence held for a long time. Another example of an improper usage is an inefficient connection resource usage, i.e. a certain connection is not released to the connection pool after having been used or the connection is held for a long time without being used. Still, another example of an improper usage is deadlock, i.e. connections are invoked in a recursive way and applications thus wait for each other to get resources that are being used by others.
In the prior art there have been proposed several connection management schemes in order to solve the problem of the improper usage of connections. One technology is to manually detect connection leak on an application server (hereinafter referred to “AS” for short). In this method, a special diagnosis program is employed to detect connection leak on an AS in a poling way. The deficiency in this detection method lies in the incapability of automatically detecting connection leak, thereby causing the omission of detection. Additionally, frequent detection will lead to extra system overheads and utilization.
A second technology is to automatically detect connection problems based on timeout. Compared with the diagnosis program described previously, this technology is automatic. An AS administrator specifies a timeout for a database connection (e.g. 75 seconds as a default value) and any application that still holds connection upon expiration of the timeout will get the timeout exception and its connection will thus be reclaimed by the system. This technology is especially suitable for the deadlock. Once the deadlock occurs, connection resources in a deadlock thread will be deprived by the system due to the timeout, and the deadlock is thus unlocked. However, the deficiency in this technology is that it is difficult to determine timeouts suitable for all transactions. For example, if a thread is a transaction that consumes a long time to be completed, then the timeout that is merely suitable for an ordinary transaction will deprive this time-consuming transaction of the connection, so the time-consuming transaction cannot proceed normally. If the AS administrator specifies a too long timeout, then the system cannot respond to a problem in time and will only discover a problem long after the problem occurred. Therefore, the overall connection utilization rate will be decreased.
Another commonly used technology is to debug a program in advance, wherein the program is analyzed using program debugging tools. If an analysis result is that the program may be subject to deadlock or leak when it is run, then the programmer is notified to modify the program. It goes without saying that to debug a distributed application in a large scale enterprise environment is a labor-intensive task. Therefore, this method has relatively poor cost efficiency.
According what is needed is a method and system to over come the problems encountered in the prior art and to improved technology for managing a database connection.